<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys,
                 com.actimind.actitime.util.TimeUtils,
                 org.apache.struts.Globals,
                 org.apache.struts.action.ActionErrors,
                 java.util.List,
                 com.actimind.actitime.task.TaskAddForm,
                 com.actimind.actitime.task.TaskAddForm"%><%@ page errorPage="/error.jsp" %>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<head>
    <title><bean:write name="title-prefix" scope="application"/> Add New Task</title>

    <script language="JavaScript" src="../js/at.js"></script>
    <script language="JavaScript" src="../js/calendar.js?r=1"></script>
    <script language="JavaScript">

    function clearDeadline()
    {
        document.forms[0]['deadlineYear'].selectedIndex = 0;
        document.forms[0]['deadlineMonth'].selectedIndex = 0;
        document.forms[0]['deadlineDay'].selectedIndex = 0;
    }

    function selectDeadline(dateStr)
    {
        selectDateFields(dateStr, document.forms[0], 'deadline');
    }

    function getDeadline()
    {
        return getDateStr(document.forms[0], 'deadline');
    }

    function selectDateFields(dateStr, frm, fieldPrefix)
    {
        date = strToDate(dateStr);

        var yearFld = frm[fieldPrefix + 'Year'];

        var yearIndex = date.getFullYear() - yearFld.options[1].value + 1;

        if (yearIndex >= 0 && yearIndex < yearFld.options.length)
        {
            yearFld.options[yearIndex].selected = true;
        }

        frm[fieldPrefix + 'Month'].options[date.getMonth() + 1].selected = true;
        frm[fieldPrefix + 'Day'].options[date.getDate()].selected = true;
    }

    function getDateStr(frm, fieldPrefix)
    {
        var year    = frm[fieldPrefix + 'Year'].options[frm[fieldPrefix + 'Year'].selectedIndex].value;
        var month   = frm[fieldPrefix + 'Month'].options[frm[fieldPrefix + 'Month'].selectedIndex].value;
        var day     = frm[fieldPrefix + 'Day'].options[frm[fieldPrefix + 'Day'].selectedIndex].value;

        if (year == 0 || month == 0 || day ==0)
            return "";

        return  year + '-' + month + '-' + day;
    }

    function doSubmit(f)
    {
        /*if (!checkField(f.name, "Task name is empty", "isNotEmpty"))
            return false;

        trimAllTextFields(f);
        normalizeAllTextFields(f);*/

        return true;
    }

    function popupCalendar(date, query)
    {
       var url = '<html:rewrite page="/calendar.do?" />?';
       var cWnd = window.open(url + query + '&dateStr=' + date, 'popup', 'width=223,height=320,scrollbars=no,status=no,resizable=no,top=200,left=200');
       cWnd.opener = self;
       cWnd.focus();
    }

    </script>
    <link rel="stylesheet" href="../css/at.css" type="text/css">
    <link rel="stylesheet" href="../css/calendar.css" type="text/css">

</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<jsp:include page="../top.jsp" flush="false">
    <jsp:param name="pageSection" value="tasks" />
    <jsp:param name="pageAction" value="taskadd" />
</jsp:include>

<html:form scope="session" action="/tasks/taskadd.do" method="post" onsubmit="return doSubmit(this)">

<input type="hidden" name="submitted" value="1" />

<input type="hidden" name="reload" value="0" />

<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff" width="770">
<tr>
    <td class="pagetitle">
        Add New Task
    </td>
</tr>
<tr>
    <td>
        <table cellspacing="2" cellpadding="2" align="left" valign="top" border="0" bgcolor="#ffffff">
        <tr>
            <td colspan="4">
                <at:errors/>
                <at:messages id="message" message="true">
                    <span class="successmsg"><bean:write name="message"/></span>
                </at:messages>
            </td>
        </tr>
        <tr>
            <td colspan="4" class="formcomment">
                <span class="formfieldtitlereq">*</span> Indicates a required field.
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="5" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Select Customer to Add Task for:
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="5" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td>
                <img height="1" width="35" src="../img/pixel.gif" />
            </td>
            <td class="formfieldtitlereq">
                *
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="customerId"><span class="errormsg">Customer:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="customerId">Customer:</logic:messagesNotPresent>
            </td>
            <td>
                <at:select property="customerId" onchange="document.forms[0].elements['reload'].value='1'; document.forms[0].submit();" maxlength="70">
                    <at:option value="0">-- please select one --</at:option>
                    <at:options collection="<%=Keys.CUSTOMERS_LIST_KEY%>" property="id" labelProperty="name" />
                </at:select>
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="5" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Select Project to Add Task for:
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="5" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td>
                <img height="1" width="35" src="../img/pixel.gif" />
            </td>
            <td class="formfieldtitlereq">
                *
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="projectId"><span class="errormsg">Project:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="projectId">Project:</logic:messagesNotPresent>
            </td>
            <td>
                <at:select property="projectId" onchange="document.forms[0].elements['reload'].value='1'; document.forms[0].elements['submitted'].value='0'; document.forms[0].submit();" maxlength="70">
                    <at:option value="0">-- please select one --</at:option>
                    <at:options collection="<%=Keys.PROJECTS_LIST_KEY%>" property="id" labelProperty="name" />
                </at:select>
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="5" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4" class="formblocktitle">
                Specify Task Details:
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="1" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td rowspan="4" >
                <img height="1" width="35" src="../img/pixel.gif" />
            </td>
            <td class="formfieldtitlereq">
                *
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="name"><span class="errormsg">Task Name:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="name">Task Name:</logic:messagesNotPresent>
            </td>
            <td>
                <html:text property="name" style="width: 470px" maxlength="255"  size="57"/>
            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereq">
                &nbsp;
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="deadline"><span class="errormsg">Deadline:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="deadline">Deadline:</logic:messagesNotPresent>
            </td>
            <td>
            <span class="text">
                <html:select property="deadlineMonth">
                    <html:option value="0">--</html:option>
                    <html:option value="1">January</html:option>
                    <html:option value="2">February</html:option>
                    <html:option value="3">March</html:option>
                    <html:option value="4">April</html:option>
                    <html:option value="5">May</html:option>
                    <html:option value="6">June</html:option>
                    <html:option value="7">July</html:option>
                    <html:option value="8">August</html:option>
                    <html:option value="9">September</html:option>
                    <html:option value="10">October</html:option>
                    <html:option value="11">November</html:option>
                    <html:option value="12">December</html:option>
                </html:select>&nbsp;
                <html:select property="deadlineDay">
                    <html:option value="0">--</html:option>
                <%
                    for (int day = 1; day <= 31; day++)
                    {
                %><html:option value="<%=(new Integer(day)).toString()%>"><%=(day < 10 ? "0" : "")%><%=day%></html:option>
                <%
                    }
                %>
                </html:select>&nbsp;
                <%
                    int yearFrom = TimeUtils.getStartYearForDropDown();
                    int yearTo = TimeUtils.getEndYearForDropDown(1);
                %>
                <html:select property="deadlineYear">
                    <html:option value="0">--</html:option>
                <%
                    for (int year = yearFrom; year <= yearTo; year++)
                    {
                %><html:option value="<%=(new Integer(year)).toString()%>"><%=year%></html:option>
                <%
                    }
                %>
                </html:select>
                <a href="javascript:popupCalendar(getDeadline(), 'yearFrom=<%=yearFrom%>&yearTo=<%=yearTo%>&selectDate=selectDeadline');"><img src="../img/cal.gif" width="20" height="20" border="0" hspace="0" vspace="0" align="top" alt="Click Here to Pick up the timestamp"></a>
                &nbsp;&nbsp;&nbsp;<a href="javascript:clearDeadline();">Clear deadline</a>
                </span>
            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereq">
                &nbsp;
            </td>
            <td class="formfieldtitle">
                <logic:messagesPresent property="billingTypeId"><span class="errormsg">Billing Type:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="billingTypeId">Billing Type:</logic:messagesNotPresent>
            </td>
            <td class="formfieldtitle">

            <logic:present name="selectedProject" scope="session">
                <bean:define id="project" name="selectedProject" scope="session" type="com.actimind.actitime.beans.ProjectBean" />
                <logic:equal value="true" name="project" property="billable">
                    <at:select property="billingTypeId" maxlength="70">
                        <at:option value="0">Non-Billable</at:option>
                        <at:options collection="<%=Keys.TYPES_LIST_KEY%>" property="id" labelProperty="name" />
                    </at:select>
                <br/>
                </logic:equal>

                <logic:notEqual value="true" name="project" property="billable">
                <html:hidden property="billingTypeId" />
                Non-Billable
                </logic:notEqual>
            </logic:present>

            <logic:notPresent name="selectedProject" scope="session">
                <html:hidden property="billingTypeId" />
                Non-Billable
            </logic:notPresent>

            </td>
        </tr>
        <tr>
            <td class="formfieldtitlereqtop">
                &nbsp;
            </td>
            <td class="formfieldtitletop">
                <logic:messagesPresent property="description"><span class="errormsg">Task Description:</span></logic:messagesPresent>
                <logic:messagesNotPresent property="description">Task Description:</logic:messagesNotPresent>
            </td>
            <td>
                <html:textarea property="description" style="width: 470px; height: 120px; " rows="7" cols="55"/>
            </td>
        </tr>
        <tr>
            <td colspan="4"><img height="1" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td colspan="4"><HR/></td>
        </tr>
        <tr>
            <td colspan="4"><img height="1" width="1" src="../img/pixel.gif" /></td>
        </tr>
        <tr>
            <td class="formfieldtitletop" colspan="3">
                After creation of this task:
            </td>
            <td>
            <table width="100%" border="0" cellpaddinh="0" cellspacing="0">
            <tr>
                <td><html:radio property="nextPage" value="<%=TaskAddForm.NEXT_PAGE_SHOW_LIST%>" /><span class="text">Show list of open tasks</span></td>
            </tr>
            <tr>
                <td><html:radio property="nextPage" value="<%=TaskAddForm.NEXT_PAGE_ADD_MORE_TASKS%>"/><span class="text">Add more tasks</span></td>
            </tr>
            </table>
            </td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td align="center" class="formbuttonpane">
        <input type="submit" value="  Create Task  " />
        <img height="1" width="100" src="../img/pixel.gif" />
        <input type="button" value="     Cancel     " onclick="if (confirm('Are you sure you want to cancel adding task?')) document.location.href='<html:rewrite href='otasklist.do'/>'" />
    </td>
</tr>
</table>

</html:form>

</body>
</html>
